



//
//  MBReleaseQZVC.m
//  发布求租
//
//  Created by MB__Lee on 2018/6/7.
//  Copyright © 2018年 MB__Lee. All rights reserved.
//

#import "MBReleaseQZVC.h"



#import "MBTwoContentCell.h"
//#import "MBCircleBTNCell.h"

#import "MBTextViewCell.h"
#import "MBTitleCell.h"

#import <MJExtension.h>

#import "MBReleaseView.h"

#import "MBRegionSelectVC.h" //期望区域

@interface MBReleaseQZVC ()<UITableViewDelegate,UITableViewDataSource,MBReleaseViewDelegate,MBRegionSelectVCDelegate>

@property(nonatomic,strong)UITableView *tableview;
@property(nonatomic,strong)MBReleaseView *bottomView;



@end

static NSString *MBTwoContentCell_Identi = @"MBTwoContentCell";
static NSString *MBCircleBTNCell_Identi = @"MBCircleBTNCell";
static NSString *MBConentMoreCell_Identi = @"MBConentMoreCell";
static NSString *MBTextViewCell_Identi = @"MBTextViewCell";
static NSString *MBTitleCell_Identi = @"MBTitleCell";

@implementation MBReleaseQZVC

- (void)viewDidLoad {
    [super viewDidLoad];
    _releseModel  = [[MBReleaseModel alloc] init];
    _releseModel.city = MBCityCode;
    _releseModel.number = @""; // 会员编号
    _releseModel.token = @""; //登录token
    
    // Do any additional setup after loading the view.
    [self.view addSubview:self.tableview];
}

-(void)setSourceMut:(NSMutableArray *)sourceMut{
    _sourceMut = sourceMut;
    
    [self.tableview reloadData];
}
-(MBReleaseView *)bottomView{
    if (!_bottomView) {
        _bottomView = [MBReleaseView MBReleaseViewCreat];
        _bottomView.delegate = self;
    }
    return _bottomView;
}
-(UITableView *)tableview{
    if (!_tableview) {
        _tableview  =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        
        _tableview.tableFooterView = self.bottomView;
        
        //1. 房屋用途
        [_tableview registerNib:[UINib nibWithNibName:MBCircleBTNCell_Identi bundle:nil] forCellReuseIdentifier:MBCircleBTNCell_Identi];
        // 2.标题、指定小区
        [_tableview registerNib:[UINib nibWithNibName:MBTitleCell_Identi bundle:nil] forCellReuseIdentifier:MBTitleCell_Identi];
        // 3.期望租金、期望面积
        [_tableview registerNib:[UINib nibWithNibName:MBTwoContentCell_Identi bundle:nil] forCellReuseIdentifier:MBTwoContentCell_Identi];
        
        // 4.期望户型、期望区域、特色标签
        [_tableview registerNib:[UINib nibWithNibName:MBConentMoreCell_Identi bundle:nil] forCellReuseIdentifier:MBConentMoreCell_Identi];
        // 5.求租描述
        [_tableview registerNib:[UINib nibWithNibName:MBTextViewCell_Identi bundle:nil] forCellReuseIdentifier:MBTextViewCell_Identi];
    }
    return  _tableview;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  self.sourceMut.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MBBaseFBQCell *cell;
    
    //cell 样式
    if (indexPath.row == 0) {
        cell = [tableView dequeueReusableCellWithIdentifier:MBCircleBTNCell_Identi];
       
        MBCircleBTNCell *btnCell  = (MBCircleBTNCell *)cell;
        btnCell.selectedIndex = self.selectedIndex;
        
        btnCell.BTNModel = self.sourceMut[indexPath.row];
        return  cell;
        
    }else if (indexPath.row == 1 || indexPath.row == 7){
        cell = [tableView dequeueReusableCellWithIdentifier:MBTitleCell_Identi];
    }else if (indexPath.row == 2|| indexPath.row == 3){
        cell =  [tableView dequeueReusableCellWithIdentifier:MBTwoContentCell_Identi];
    }else if (indexPath.row == 4 || indexPath.row == 5 || indexPath.row == 6){
        cell = [tableView dequeueReusableCellWithIdentifier:MBConentMoreCell_Identi];
    }else if (indexPath.row  == 8){
        cell  = [tableView dequeueReusableCellWithIdentifier:MBTextViewCell_Identi];
    }
    
    // 添加模型
    if (indexPath.row  == 0) {
        cell.BTNModel = self.sourceMut[indexPath.row];
    }else{
        cell.CMModel = self.sourceMut[indexPath.row];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return  cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat hight;
    if (indexPath.row == 0) {
        hight = 94;
    }else if (indexPath.row == 8){
        hight = 214;
    }else{
        hight = 50;
    }
    return  hight;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //此处让子类实现
    if (indexPath.row == 4) {
        
    }else if (indexPath.row == 5){
        
    }else if (indexPath.row == 6){
        MBRegionSelectVC *regionvc  = [[MBRegionSelectVC alloc]init];
        regionvc.delegate = self;
        
        [self.navigationController pushViewController:regionvc animated:YES];
        
    }
}

#pragma mark --发布按钮所在view 的代理方法
-(void)MBReleaseViewMakeRelease:(MBReleaseView *)reView{
    //1.抽取填写的数据
    
    [self addInfoToModel];
    
    
    //2.将模型中的数组序列化
    [_releseModel MBJsonString];
    
    //3.将数据上传到服务器
    NSMutableDictionary *dict  = [_releseModel mj_keyValues];

    [MBNetTool MBPost:QiuZu_add paramater:dict success:^(id response) {
        
    } failure:^(NSError *error) {
        
    }];
    
    
    
}
-(void)MBReleaseViewShowProtocolVC:(MBReleaseView *)reView{
    //显示协议控制器
    
}
-(void)addInfoToModel{
    //1.标题
    MBCommonCellModel *one  = self.sourceMut[1];
    _releseModel.title = one.sourceTitle;
    
    //2.期望面积
    MBCommonCellModel *two =self.sourceMut[2];
    _releseModel.square_start = two.sourceMiddle;
    _releseModel.square_end = two.sourceUnit;
    
    //3.期望租金
    MBCommonCellModel *three = self.sourceMut[3];
    _releseModel.rent_start = three.sourceMiddle;
    _releseModel.rent_end = three.sourceUnit;
    
    //4.期望户型 --子类代理方法填写
    //5.特色标签 --子类代理方法填写
    // 6.期望区域 ---本类代理方法填写
    // 7.指定小区
    MBCommonCellModel *seven = self.sourceMut[7];
    _releseModel.xq = seven.sourceTitle;
    ///8. 求租描述
    MBCommonCellModel *eight = self.sourceMut[8];
    _releseModel.describe = eight.sourceTitle;
    
    
    
}
#pragma mark ---区域选择代理方法
-(void)MBRegionSelectVCSendDistrictModel:(ArDistrictModel *)disModel regionModel:(ArRegionModel *)reModel{
    
    _releseModel.district = disModel.code;
    _releseModel.region = reModel.code;
    
    if (disModel.code.length) {
        NSIndexPath *indexPath  =[NSIndexPath indexPathForRow:6 inSection:0];
        MBConentMoreCell *cell = (MBConentMoreCell *)[self.tableview cellForRowAtIndexPath:indexPath];
        [cell changeStateASSelected];
    }
    
    
}
#pragma mark --MBCircleBTNCellDelegate
-(void)MBCircleBTNCellDelegateSendButtonIndex:(NSUInteger)index{
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
